/*
var arr = ["小明","小红","小亮"];

console.log(arr);
console.log(arr[0]);
console.log(arr[1]);

var age = [18,18,19];
console.log(age[0]);
console.log(age[1]);
console.log(age[2]);

var mix = ["小明",18,"小红",18,"小亮",19];
console.log(mix[0]);
console.log(mix[1]);
console.log(mix[2]);

*/

/*
var b = [1,2,3,60,2,5,7,10,20,30];
console.log(b);

for(var yz = 0; yz<b.length; yz++){
    console.log(b[yz]);
}


//获取数组的长度
console.log(b.length);

//赋值数组的长度
b.length = 6;
console.log(b.length);
console.log(b);

*/

/*
var yz = ["首页","产品中心","新闻中心","关于我们","联系我们"];
var nav = document.querySelector('#nav');

var str = '<ul>';
for(var i = 0;i<yz.length;i++){
    str+='<li><a href="">'+ yz[i]+'</a></li>'
}
str +='</ul>';

nav.innerHTML =str
*/
/*
//空的数组
var  arr = new Array();
var arr1 =[];

arr[0] = "小明";
arr[1] = "小红";
arr[2] = "x";
arr[3] = "3";

arr[1] = "小灰灰";

var x;
for(x in arr){
    console.log(arr[x]);
}

*/


/*
var arr = [1,2,3];
var arr2 = [10,20,30];

//合并数组
var arr3 = arr.concat(arr2);

//把arr2的值合并到arr里面
arr = arr.concat(arr2);



//增加数组
arr3.pop();
arr3.pop();

//删除数组
arr3.push(100);
arr3.push(1000);

//颠倒顺序
arr3.reverse();


console.log(arr3);
*/

/*
//从小到大排序
var arr = [100,39,78,43,20,8];

function s(a,b) {
    return a-b;
}
console.log(arr.sort(s));
*/


/*
//查找最大值和最小值，输出到控制台

var arr = [100,45,32,23,6];

var min = arr[0];
var max = arr[0];
for (var i=0;i<arr.length;i++){
    if (min<arr[i]){
       min = arr[i]
    }else {
        min = arr[i];
    }
}

for (var i=0;i<arr.length;i++){
    if (max<arr[i]){
        max = arr[i];
    }else {
        max = max ;
    }
}

console.log(min);
console.log(max);
*/

/*
//老师做法：求最大值，跟最小值
var  arr = [2,34,67,35,677];
//假设数组的第一个值为最大值和最小值
var min = arr[0];
var max = arr[0];

for (var i=1;i<arr.length;i++){
    //当前元素比最大值max大的情况下，就修改max的值
    if (arr[i]>max){
        max= arr[i];
    }
    //当前元素比最小值min小的情况下，就修改min的值
    if (arr[i]<min){
        min = arr[i];
    }
}
console.log("最大值"+max);
console.log("最小值"+min);
*/




//冒泡排序

var arr = [43,34,54,23,89,90,4];
for (var yz=0;yz<arr.length-1;yz++){
    
    for (var zy=0;zy<arr.length-1-yz;zy++){
        //如果前一个数大于后一个数，那么就给这2个数交换位置
        if(arr[zy]>arr[zy+1]){
            var temp = arr[zy];
            arr[zy] = arr[zy+1];
            arr[zy+1] = temp;
        }
    }
}
console.log(arr);


/*
//解析冒泡排序
var arr = [21,12,18,1,5,3,7];

     if (arr[0]>arr[1]){
         var temp = arr[0];
         arr[0] = arr[1];
         arr[1] = temp;
     }

     if (arr[1]>arr[2]){
         var temp = arr[1];
         arr[1] = arr[2];
         arr[2] = temp;
     }
    if (arr[2]>arr[3]){
        var temp = arr[2];
        arr[2] = arr[3];
        arr[3] = temp;
    }
    if (arr[3]>arr[4]){
        var temp = arr[3];
        arr[3] = arr[4];
        arr[4] = temp;
    }
    if (arr[4]>arr[5]){
        var temp = arr[4];
        arr[4] = arr [5];
        arr[5] = temp;
    }
    if (arr[5]>arr[6]){
        var temp = arr[5];
        arr [5] = arr [6];
        arr [6] = temp;
    }
    if (arr[0]>arr[1]){
        var temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }

    if (arr[1]>arr[2]){
        var temp = arr[1];
        arr[1] = arr[2];
        arr[2] = temp;
    }
    if (arr[2]>arr[3]){
        var temp = arr[2];
        arr[2] = arr[3];
        arr[3] = temp;
    }
    if (arr[3]>arr[4]){
        var temp = arr[3];
        arr[3] = arr[4];
        arr[4] = temp;
    }
    if (arr[4]>arr[5]){
        var temp = arr[4];
        arr[4] = arr [5];
        arr[5] = temp;
    }
    if (arr[0]>arr[1]){
        var temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }

    if (arr[1]>arr[2]){
        var temp = arr[1];
        arr[1] = arr[2];
        arr[2] = temp;
    }
    if (arr[2]>arr[3]){
        var temp = arr[2];
        arr[2] = arr[3];
        arr[3] = temp;
    }
    if (arr[3]>arr[4]){
        var temp = arr[3];
        arr[3] = arr[4];
        arr[4] = temp;
    }
    if (arr[0]>arr[1]){
        var temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }

    if (arr[1]>arr[2]){
        var temp = arr[1];
        arr[1] = arr[2];
        arr[2] = temp;
    }
    if (arr[2]>arr[3]){
        var temp = arr[2];
        arr[2] = arr[3];
        arr[3] = temp;
    }
    if (arr[0]>arr[1]){
        var temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }

    if (arr[1]>arr[2]){
        var temp = arr[1];
        arr[1] = arr[2];
        arr[2] = temp;
    }
    if (arr[0]>arr[1]){
        var temp = arr[0];
        arr[0] = arr[1];
        arr[1] = temp;
    }
console.log(arr);
*/